package com.ddstation.clinic_info.service;

import java.util.List;

import javax.inject.Inject;

import com.ddstation.common.property.SystemProperties;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ddstation.clinic_info.mapper.ClinicInfoMapper;
import com.ddstation.clinic_info.model.ClinicInfoModel;
import com.ddstation.common.model.ImageModel;
import com.ddstation.common.service.ImageService;
import com.ddstation.crm.institution.entity.DtHealthManageInstitutionEntity;
import com.ddstation.crm.institution.mapper.DtHealthManageInstitutionMapper;

@Service
public class ClinicInfoServiceImpl implements ClinicInfoService {
	
	@Override
	@Transactional(readOnly=true)
	public List<ClinicInfoModel> searchInstitutions(
			   String invsInstitutionId,
			   String institutionId,
			   String institutionName,
			   Integer underInvs,
			   Integer prescriptionInvs,
			   String institutionTypeFirst){
		if("yes".equals(SystemProperties.IS_INNER_DATA)){
			return clinicInfoMapper.selectInstitutionsIsInner(invsInstitutionId,institutionId,institutionName,underInvs,prescriptionInvs,institutionTypeFirst);//内网查询
		}else{
			return clinicInfoMapper.selectInstitutions(invsInstitutionId,institutionId,institutionName,underInvs,prescriptionInvs,institutionTypeFirst);//外网查询
		}
	}
	
	// 查询营业执业 、执业资格许可证图片
	public List<ImageModel> fetchImage(String institutionId,String type){
		DtHealthManageInstitutionEntity a = dtHealthManageInstitutionMapper.select(institutionId);
		String[] keys = new String[1];
		if ("business_licence".equals(type)){
			// 营业照未上传时
			keys[0] = a.getBusinessLicence();
		} else {
			keys[0] = a.getOccupationalLicence();
		}
		return imageService.fetchImageByKey(keys);
	}
	
	// 更新机构信息
	public int updateClinicInfo(DtHealthManageInstitutionEntity a){
		return dtHealthManageInstitutionMapper.update(a);
	}
	
	/**
	 * 查询1家机构 卫监登记实施FLG
	 * */
	public ClinicInfoModel searchInvsSettingsInfo(String institutionId){
		if("yes".equals(SystemProperties.IS_INNER_DATA)){
			return clinicInfoMapper.selectInvsSettingsInfoIsInner(institutionId);//内网查询
		}else{
			return clinicInfoMapper.selectInvsSettingsInfo(institutionId);//外网查询
		}
	}

	@Inject private ImageService imageService;
	@Inject private DtHealthManageInstitutionMapper dtHealthManageInstitutionMapper;
	@Inject private ClinicInfoMapper clinicInfoMapper;
}
